
$.get("/static/my/get_users.json", function(_data){
	console.log("====", _data);
	//$('#dg').datagrid('loadData', _data);
	$('#dg').datagrid({
		data: _data,
		pageList: [2,5,10,15,20],
		pageSize: 2
	});
});


var toolbar1_1 = [{
	text:'Save',
	iconCls:'icon-save',
	handler:function(){alert('save')}
}];


var url_1;
function newUser(){
	$('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
	$('#fm').form('clear');
	url_1 = 'save_user.php';
}
function editUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
		$('#fm').form('load',row);
		url_1 = 'update_user.php?id='+row.id;
	}
}
function saveUser(){
	$('#fm').form('submit',{
		url: url_1,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){
			var result = eval('('+result+')');
			if (result.errorMsg){
				$.messager.show({
					title: 'Error',
					msg: result.errorMsg
				});
			} else {
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the user data
			}
		}
	});
}
function destroyUser(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
			if (r){
				$.post('destroy_user.php',{id:row.id},function(result){
					if (result.success){
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({	// show error message
							title: 'Error',
							msg: result.errorMsg
						});
					}
				},'json');
			}
		});
	}
}